/**
 *
 */
package com.zhengtoon.mctoon.conv.service;

import com.zhengtoon.mctoon.conv.bean.ConvPraiseInfo;
import com.zhengtoon.mctoon.conv.dao.ConvPraiseInfoMapper;
import com.zhengtoon.mctoon.conv.service.ConvPraiseInfoService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 点赞 impl实现
 *
 * @author 赵康峰
 * @since 2017-05-26
 * Copyright: Copyright (c) 2017
 * Company:北京政务通科技有限公司
 */
@Service
public class ConvPraiseInfoServiceImpl implements ConvPraiseInfoService {

    private static Logger log = LoggerFactory.getLogger(ConvPraiseInfoServiceImpl.class);

    @Autowired
    private ConvPraiseInfoMapper convPraiseInfoMapper;

    @Override
    public int praise(String id, String userId) {

        int isPraise = convPraiseInfoMapper.isPraise(Long.valueOf(id), userId);
        log.info("随手拍记录表id" + id + "状态为：" + isPraise);
        if (isPraise == 0) {
            ConvPraiseInfo convPraiseInfo = new ConvPraiseInfo();
            convPraiseInfo.setConvId(Long.valueOf(id));
            convPraiseInfo.setPraiseUserId(userId);
            convPraiseInfo.setCreateTime(new Date().getTime());
            convPraiseInfo.setUpdateTime(new Date().getTime());
            return convPraiseInfoMapper.addPraise(convPraiseInfo);
        } else {
            return convPraiseInfoMapper.deletePraise(Long.valueOf(id), Long.valueOf(userId));
        }
    }

}